package com.lecture.java8.date;

import java.util.function.IntPredicate;

public class Demo3 {
    public static void main(String[] args) {
        int x = 4; // 获取要检查的值
        ValueCheckerLambda checker = ValueCheckerLambda.check(x);
        checker.greaterThan(v -> v > 11, "Value is greater than 1")
                .greaterThan(v -> v > 22, "Value is greater than 2")
                .greaterThan(v -> v > 3, "Value is greater than 3");
        if (checker.getConditions() != null) {
            System.out.println(checker.getConditions());
        }

        /*Double z = 7.9; // 获取第一个double类型的值
        Double y = null; // 获取第二个double类型的值
        int result = z.compareTo(y);
        if (result < 0) {
            System.out.println("x小于y");
        } else if (result > 0) {
            System.out.println("x大于y");
        } else {
            System.out.println("x等于y");
        }*/
    }
}


class ValueCheckerLambda {
    private final int value;
    private boolean passed;
    private String conditions;

    private ValueCheckerLambda(int value) {
        this.value = value;
        this.passed = true;
    }

    public static ValueCheckerLambda check(int value) {
        return new ValueCheckerLambda(value);
    }

    public ValueCheckerLambda greaterThan(IntPredicate predicate, String message) {
        if (predicate.test(value)) {
            conditions = message;
            return this;
        } else {
            passed = false;
            return this;
        }
    }

    public boolean passed() {
        return passed;
    }

    public String getConditions() {
        return conditions;
    }
}